package com.jxwifi.cloud.quickclean.popwindow;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.adapter.OrderStartsAdapter;
import com.jxwifi.cloud.quickclean.bean.OptRecordsBean;
import com.popwindow.BasicPopmodule;

import java.util.ArrayList;
import java.util.List;

public class PopOrderStartModule extends BasicPopmodule {

    private Context mContext;
    //private PopStartListener mPoplistener;
    private OrderStartsAdapter mAdapter;  //布局 list_order_starts_items
    private List<OptRecordsBean> mList=new ArrayList<>();

    public PopOrderStartModule(Context context,List<OptRecordsBean> list){
        this.mContext=context;
        //this.mPoplistener=l;
        this.mList=list;
        initView();
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_show_order_start, new LinearLayout(mContext), false);
        setListener();
    }

    public void setListener(){
        View mVwPopBlank=(View)mContentView.findViewById(R.id.vw_pop_blank);
        TextView mTvOrderStartsCancel=(TextView)mContentView.findViewById(R.id.tv_order_starts_cancel);
        RecyclerView mRvOrderStartsList=(RecyclerView)mContentView.findViewById(R.id.rv_order_starts_list);

        mRvOrderStartsList.setLayoutManager(new LinearLayoutManager(mContext));
        if (mList.size()>0){
            mRvOrderStartsList.setAdapter(mAdapter = new OrderStartsAdapter(R.layout.list_order_starts_items,mList,mList.get(0).getCreateTime()));
        }else{
            mRvOrderStartsList.setAdapter(mAdapter = new OrderStartsAdapter(R.layout.list_order_starts_items,mList,""));
        }
        mAdapter.openLoadAnimation();
        mAdapter.openLoadAnimation(BaseQuickAdapter.FOOTER_VIEW);

        mVwPopBlank.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
        mTvOrderStartsCancel.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
    }
}
